import 'package:edu_assistant/pages/chat_page.dart';
import 'package:flutter/material.dart';

class ToutiaoMyPage extends StatefulWidget {
  @override
  _ToutiaoMyPageState createState() => _ToutiaoMyPageState();
}

class _ToutiaoMyPageState extends State<ToutiaoMyPage> {
  bool isHeaderVisible = true;
  ScrollController _scrollController = ScrollController();

  @override
  void initState() {
    super.initState();
    _scrollController.addListener(() {
      if (_scrollController.offset > 50 && isHeaderVisible) {
        setState(() {
          isHeaderVisible = false;
        });
      } else if (_scrollController.offset <= 50 &&!isHeaderVisible) {
        setState(() {
          isHeaderVisible = true;
        });
      }
    });
  }

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      body: NotificationListener<ScrollNotification>(
        onNotification: (scrollNotification) {
          if (scrollNotification is ScrollUpdateNotification) {
            // 根据滚动位置计算透明度等渐变效果
            double opacity = 1.0 - scrollNotification.metrics.pixels / 200;
            if (opacity < 0) {
              opacity = 0;
            }
            // 更新头部组件的透明度等属性
            // 这里假设头部组件是一个名为_headerWidget的Widget，需要根据实际情况进行更新
            setState(() {
              // _headerWidget.opacity = opacity;
            });
          }
          return true;
        },
        child: ListView(
          controller: _scrollController,
          children: [
            Container(
              height: 200,
              color: Colors.blue,
              child: AnimatedOpacity(
                opacity: isHeaderVisible? 1.0 : 0.0,
                duration: Duration(milliseconds: 300),
                child: Column(
                  children: [
                    Text('亲切晚风爱意弄'),
                    Text('470 关注 28 粉丝 56 获赞'),
                    // 其他头部信息
                  ],
                ),
              ),
            ),
            // 其他功能模块
            ListTile(
              leading: Icon(Icons.message),
              title: Text('消息私信'),
              trailing: Text('34'),
            ),
            ListTile(
              leading: Icon(Icons.history),
              title: Text('浏览历史'),
            ),
            // 更多功能项
            Container(
              color: Colors.orange[100],
              child: Padding(
                padding: EdgeInsets.all(10),
                child: Row(
                  mainAxisAlignment: MainAxisAlignment.spaceBetween,
                  children: [
                    Text('去聊天'),
                    ElevatedButton(
                      onPressed: () {
                        // 去参与的逻辑
                        Navigator.push(
                          context,
                          MaterialPageRoute(
                            builder: (context) => const ChatPage(),
                          ),
                        );
                      },
                      child: Text('去参与'),
                    ),
                  ],
                ),
              ),
            ),
            // 其他内容
          ],
        ),
      ),
    );
  }
}